import React, { Component } from "react";

export default class TestCom extends Component {
  constructor(props) {
    super();
    this.state = {
      num: 1,
    };
  }

  //类似于vue mounted
  componentDidMount() {
    console.log("已挂载");
  }

  //已更新
  componentDidUpdate(prevProps, prevState) {
    console.log("已更新-prevProps", prevProps);
    console.log("已更新-prevState", prevState);
  }
  //将要卸载
  componentWillUnmount() {
    console.log("卸载前");
  }

  changeValue() {
    this.setState({
      num: this.state.num + 1,
    });
  }

  render() {
    return (
      <div onClick={this.changeValue.bind(this)}>
        我是一个测试组件--{this.state.num}
      </div>
    );
  }
}
